package com.excesys.exsecs.alarm.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.alarm.dto.AlarmEnableDto;
import com.excesys.exsecs.alarm.entity.AlarmEnable;
import com.excesys.exsecs.alarm.entity.AlarmTypeConf;
import com.excesys.exsecs.alarm.service.AlarmEnableService;
import com.excesys.exsecs.alarm.service.AlarmTypeConfService;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import com.excesys.exsecs.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 告警类型配置表
 *
 * @author lxc
 * @date 2024-10-14 16:40:36
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/alarmEnable" )
@Tag(description = "alarmEnable" , name = "使能配置表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AlarmEnableController {

    private final AlarmEnableService alarmEnableService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param alarmEnable 使能配置表管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('alarm_alarmEnable_view')" )
    public R getPage(@ParameterObject Page page, @ParameterObject AlarmEnable alarmEnable) {
        return R.ok(alarmEnableService.getAlarmEnableInfoPage(page,alarmEnable));
    }


    /**
     * 通过id查询告警类型配置表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('alarm_alarmEnable_view')" )
    public R getById(@PathVariable("id" ) String id) {
        return R.ok(alarmEnableService.getInfoByid(id));
    }

    /**
     * 新增告警类型配置表
     * @param alarmEnableDto 告警类型配置表
     * @return R
     */
    @Operation(summary = "新增告警类型配置表" , description = "新增告警类型配置表" )
    @SysLog("新增告警类型配置表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('alarm_alarmEnable_add')" )
    public R save(@RequestBody AlarmEnableDto alarmEnableDto) {
        return R.ok(alarmEnableService.saveAlarmEnable(alarmEnableDto));
    }

    /**
     * 修改告警类型配置表
     * @param alarmEnableDto 告警类型配置表
     * @return R
     */
    @Operation(summary = "修改告警类型配置表" , description = "修改告警类型配置表" )
    @SysLog("修改告警类型配置表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('alarm_alarmEnable_edit')" )
    public R updateType(@Validated @RequestBody AlarmEnableDto alarmEnableDto) {
        return R.ok(alarmEnableService.updateAlarmEnable(alarmEnableDto));
    }

    /**
     * 通过id删除告警类型配置表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除告警类型配置表" , description = "通过id删除告警类型配置表" )
    @SysLog("通过id删除告警类型配置表" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('alarm_alarmEnable_del')" )
    public R removeById(@RequestBody String[] ids) {
        return R.ok(alarmEnableService.removeBatchByIds(CollUtil.toList(ids)));
    }

	/**
	 * 通过id删除工单
	 * @param  id
	 * @return R
	 */
	@Operation(summary = "通过id删除工单", description = "通过id删除工单")
	@SysLog("通过id删除工单")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('alarm_alarmEnable_del')")
	public R removeById(@PathVariable Integer id) {
		return R.ok(alarmEnableService.removeAlarmEnableById(id));
	}
}